package com.gimi.cloud.bbp.manage.consumer.service.sys.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.sys.SysConfigDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.sys.ConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * @author chendi
 *
 */
@Service
public class ConfigServiceImpl implements ConfigService {
	
	private static final Logger logger = LoggerFactory.getLogger(ConfigServiceImpl.class);
	@Autowired
	private SystemFeignService systemFeignService;
	
	//查询配置列表
	@Override
	public Response getConfigList(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) {
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestBody, SysConfigDTO.class);
		return systemFeignService.getConfigList(configDTOJson);
	}

	@Override
	public Response getConfigPageList(@RequestBody String requestData, HttpServletRequest request, HttpServletResponse response) {
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestData, SysConfigDTO.class);
		return systemFeignService.getConfigPageList(configDTOJson);
	}
	//添加系统配置
	@Override
	public Response addConfig(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response){
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestBody, SysConfigDTO.class);
		return systemFeignService.addConfig(configDTOJson);

	}
	@Override
	public Response updateConfig(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) {
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestBody, SysConfigDTO.class);
		
		if (!StringUtil.isEmpty(configDTOJson.getCfName())&&configDTOJson.getCfName().length() > 100 ) {
			throw new MsgException(ResponseCodeEnum.FAILURE, "您输入的内容非法(可能是长度过长)!");
		}
		return systemFeignService.configUpdate(configDTOJson);
		
	}
	@Override
	public Response getConfigSingle(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) {
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestBody, SysConfigDTO.class);
		return systemFeignService.getConfigSingle(configDTOJson);

	}
	@Override
	public Response deleteConfig(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response) {
		SysConfigDTO configDTOJson = JsonUtil.jsonToBean(requestBody, SysConfigDTO.class);
		return systemFeignService.deleteConfig(configDTOJson);
	}


}
